import { getArtistAllSongs, getArtistMv, getArtistAlbum, getArtistDesc } from '../../api/services/api'
export default ({
    namespaced: true,
    state: {
        currentType: {
            order: 'time',
            limit: 30,
            currentPage: 1
        },
        artistInformation: {
            name: '',
            albumSize: '',
            briefDesc: '',
            img1v1Url: '',
            musicSize: '',
            mvSize: '',
        },
        songList: [],
        mvsList: [],

        album: {
            currentPage: 1,
            limit: 12,
            albumList: [],
        },
        singerDesc: {
            jianjie: [],
            text: [],
        }


    },
    mutations: {
        changeArtist(state, val) {
            state.artistInformation = { ...val };
        },
        changeSongList(state, val) {
            state.songList = [...val];
        },
        changeMvsList(state, val) {
            state.mvsList = [...val];
        },
        changeAlbum(state, val) {
            state.album.albumList = [...state.album.albumList, ...val];
        },
        changeAlbumCurrentPage(state, val) {
            state.album.currentPage++;
        },
        changeSingerDesc(state, val) {
            let arr = val.briefDesc.split('\n');
            console.log('歌手信息数组', arr);
            state.singerDesc.jianjie = [...arr];
            state.singerDesc.text = val.introduction
        }
    },
    actions: {
        async getArtistAllSongs(context, id) {
            const { order, limit, currentPage } = context.state.currentType;
            const data = await getArtistAllSongs(id, order, limit, currentPage);
            console.log('歌手全部歌曲', data);
            context.commit('changeArtist', data.artist);
            context.commit('changeSongList', data.hotSongs);
        },
        async getArtistMv(context, id) {
            const { mvSize } = context.state.artistInformation;
            console.log('mv~~~~~~~~~~~~~~', mvSize);
            const data = await getArtistMv(id, mvSize);
            console.log('歌手全部MV', data);
            context.commit('changeMvsList', data.mvs);
        },
        async getArtistAlbum(context, id) {
            const { limit, currentPage, } = context.state.album;
            const data = await getArtistAlbum(id, limit, currentPage);
            console.log(data);
            context.commit('changeAlbum', data.hotAlbums);
        },
        async getArtistDesc(context, id) {
            const data = await getArtistDesc(id);
            console.log('歌手信息', data);
            context.commit('changeSingerDesc', data);
        }

    },

})
